#include <cstdio>
#include <iostream>

using namespace std;

int g[1000][1000];
int color[1000];
bool used[1000];
int n;

void dfs(int v, int c)
{
	used[v] = true;
	color[v] = c;
	for (int u = 0; u < n; u++)
		if (g[v][u] == 1 && !used[u])
			dfs(u, c);
}

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> g[i][j];
	for (int  i = 0; i < n; i++)
		used[i] = false;
	int col = 0;
	for (int i = 0; i < n; i++)
		if (!used[i]) dfs(i, ++col);
	cout << col << endl;
	for (int c = 1; c <= col; c++)
	{
		for (int i = 0; i < n; i++)
			if (color[i] == c)
				cout << i + 1 << " ";
		cout << endl;
	}
}


